﻿@using viBook.Models
@model IEnumerable<ContentTag>
@{
    ViewBag.Title = "Tags";
    ViewBag.Menu = "Management";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
@(Html.Telerik().Grid(Model)
               .Name("tag-data-grid")
               .ToolBar(commands => commands.Insert())
               .DataKeys(keys => keys.Add(contentTag => contentTag.Id))
               .Columns(columns =>
                            {
                                columns.Bound(contentTag => contentTag.ContentTagName)
                                    .Template(
                                            @<text>
@Html.ActionLink(item.ContentTagName, "ContentTags", "Admins")
</text>
                                    )
                                    .ClientTemplate(string.Format("<a href='/ContentTags/Details/<#= Id #>'><#= ContentTagName #></a>"))
                                    .Title("Tag");
                                columns.Bound(contentTag => contentTag.NumberOfBook).ReadOnly();
                                columns.Command(c =>
                                                    {
                                                        c.Edit();
                                                        c.Delete();
                                                    }).Width(200);
                            })
.DataBinding(dataBinding =>
{
    dataBinding.Server().Select("ContentTags", "Admins");
    dataBinding.Ajax().Select("SelectContentTagAjax", "Admins").Enabled(true);
    dataBinding.Ajax().Insert("InsertContentTagAjax", "Admins").Enabled(true);
    dataBinding.Ajax().Update("UpdateContentTagAjax", "Admins").Enabled(true);
    dataBinding.Ajax().Delete("DeleteContentTagAjax", "Admins").Enabled(true);
})
.ClientEvents(events => events.OnError("onError"))
.Editable(editing => editing.Mode(GridEditMode.InLine))
.Scrollable()
.Sortable()
.Pageable()
.Footer(true)
)

<script type="text/javascript">
    function onError(e) {
        if (e.textStatus == 'error') {
            if (e.XMLHttpRequest.status == "500") {
                alert(e.XMLHttpRequest.responseText);
                e.preventDefault();
            }
        }
    }

</script>